<template>
  <div>
    <el-container class="wrap">
      <el-aside width="200px">
        <el-menu
          default-active="0"
          class="el-menu-vertical-demo"
          background-color="#FF6B4F"
          text-color="#fff"
          active-text-color="#ffd04b"
          unique-opened
          router
        >
          <el-menu-item index="/">
            <i class="el-icon-s-help"></i>
            <span slot="title">首页</span>
          </el-menu-item>

          <div v-for="item in userInfo.menus" :key="item.id">
            <!-- 目录 -->
            <el-submenu :index="item.id + ''" v-if="item.children">
              <template slot="title">
                <i :class="item.icon"></i>
                <span>{{ item.title }}</span>
              </template>
              <el-menu-item
                v-for="it in item.children"
                :key="it.id"
                :index="it.url"
                >{{ it.title }}</el-menu-item
              >
            </el-submenu>
            <!-- 菜单 -->
            <el-menu-item :index="item.url" v-else>{{
              item.title
            }}</el-menu-item>
          </div>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <el-tag>用户名：{{ userInfo.username }}</el-tag>
          <el-button @click="goOut()">退出</el-button>
        </el-header>
        <el-main>
          <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item
              ><a href="/">{{ $route.meta.title }}</a></el-breadcrumb-item
            >
          </el-breadcrumb>

          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import { successAlert, warningAlert } from "../../utils/alert.js";
export default {
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      userInfo: "userInfo",
    }),
  },
  methods: {
    ...mapActions({
      asyncChnagUserInfo: "asyncChnagUserInfo",
    }),
    goOut() {
      successAlert("退出成功");
      this.asyncChnagUserInfo({});
      this.$router.push("/login");
    },
  },
};
</script>

<style lang="less" scoped>
@import url("../../less/index.less");
.wrap {
  width: 100vw;
  height: 100vh;
}
.el-header {
  background-color: @color3;
  color: #333;
}

.el-aside {
  background-color: @color1;
  color: #333;
}

.el-main {
  background-color: @color5;
  color: #333;
}
</style>